<template>
  <button
    class="launch-btn w-[279px] h-[48px]"
    :class="{ 'launch-btn-pc': equ === 'pc' }"
  >
    <div class="bg-after relative w-full h-full p-[7px 10.5px] py-[7px] px-[10.5px]">
      <span
        v-for="x in 4"
        :key="x"
        class="triangle absolute block z-1 w-[7px] h-[7px] bg-white"
        :style="{ '--x-r': `${90 * x}deg` }"
        :class="{ 'top-0': x < 3, 'right-0': [2, 3].includes(x), 'left-0': [1, 4].includes(x), 'bottom-0': x > 2 }"
      ></span>
      <div class="content w-full h-full relative z-0 text-white text-[16px] tracking-[4px] flc">
        <div class="content-border left absolute top-0 left-0 h-full border-white border-[1px] border-r-0 z-1"></div>
        <div
          class="content-border right absolute top-0 right-0 z-1 h-full border-white border-[1px] border-r-0 transform rotate-[180deg]"
        >
        </div>
        <div class="content-bg absolute w-full h-full top-0 left-0 z-0"></div>
        <div class="content-text relative z-1 font-bold">
          <slot />
        </div>
      </div>
    </div>
  </button>
</template>

<script
  lang="ts"
  setup
  name="AnimoteBtn"
>
import { equ } from '../../../../package-env';

</script>

<style scoped lang="scss">
@keyframes content {
  from {
    transform: scaleX(0);
  }

  to {
    transform: scaleX(1);
  }
}

@keyframes content-bg {
  0% {
    opacity: 0;
  }

  50% {
    opacity: 0.8;
  }

  80% {
    opacity: 0.6;
  }

  100% {
    opacity: 1;
  }
}

@keyframes content-text {
  0% {
    @include set-clip(inset(100%));
  }

  100% {
    @include set-clip(inset(-10%));
  }
}

.launch-btn {
  .bg-after {
    transition: all 0.3s;

    $t: 0.8s;

    .triangle {
      @include triangle(50%, 50%);
      transform: rotate(var(--x-r));
      animation-duration: $t;
      animation-timing-function: linear;
      animation-delay: calc($t / 2);
      animation-fill-mode: both;
      animation-iteration-count: 1;
      @include set-clip(polygon(0 0, 0 100%, 100% 100%));

      &:nth-child(1) {
        animation-name: triangle-top-left;
      }

      &:nth-child(2) {
        animation-name: triangle-top-right;
      }

      &:nth-child(3) {
        animation-name: triangle-bottom-right;
      }

      &:nth-child(4) {
        animation-name: triangle-bottom-left;
      }
    }

    .content {
      .content-bg {
        background: linear-gradient(270deg, rgba(255, 255, 255, 0) 0.04%, rgba(255, 255, 255, 0.21) 57.31%, rgba(255, 255, 255, 0) 100%);
        animation: content $t linear calc($t / 2) both;
      }

      .content-border {
        width: 5px;
        box-shadow: 0px 0px 2px 0 rgba(255, 255, 255, 1);
        @include set-clip(polygon(-2px -2px, -2px 105%, 95% 105%, 95% -2px));
        animation: content-bg $t * 0.6 linear calc($t * 1.5) 1 both;
      }

      .content-text {
        animation: content-text calc($t * 0.6) linear $t 1 both;
      }
    }
  }

  &-pc {

    width: 100%;
    height: 100%;

    .bg-after {
      transition: all 0.15s;

      .triangle {
        animation-duration: 0.4s;
        animation-delay: 0.15s;
      }

      .content {
        font-size: 24px;

        &:hover {
          .content-bg {
            background: linear-gradient(270deg, rgba(43, 111, 231, 0.1) 0%, rgba(19, 105, 255, 0.4) 50%, rgba(43, 111, 231, 0.1) 100%);
            animation: content 0.2s linear 0.25s both;
          }
        }

        .content-bg {
          background: linear-gradient(270deg, rgba(43, 111, 231, 0.1) 0%, rgba(19, 105, 255, 0.2) 50%, rgba(43, 111, 231, 0.1) 100%);
          animation: content 0.2s linear 0.25s both;


        }

        .content-border {
          animation: content-bg 0.1s linear 0.5s 1 both;
        }

        .content-text {
          animation: content-text 0.2s linear 0.4s 1 both;
        }
      }
    }
  }
}
</style>
